home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tcclib.exe / VERTMENU.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-08  |  1.6 KB  |  70 lines

  1. #include "tcclib.h"
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5. #include <ctype.h>
  6. #include <stdio.h>
  7.  
  8. void VertMenu( MenuRec MP[], int numchoices, int x, int y, int xx, int yy )
  9. {
  10.     register int i, ptr=0, longest=0;
  11.     int begx, begy;
  12.     int ch;
  13.     char *screen;
  14.  
  15.     for (i=0; i<numchoices; ++i) {
  16.         if ( strlen( MP[i].Item ) > longest )
  17.             longest = strlen( MP[i].Item );
  18.     }
  19.  
  20.     begx = x;
  21.     begy = y;
  22.     while ( begx+1+longest    > 80 ) begx--;
  23.     while ( begy+1+numchoices > 25 ) begy--;
  24.     if ( begx < 0 ) begx = 0;
  25.     if ( begy < 0 ) begy = 0;
  26.     screen = (char *) calloc( 4000, 1 );
  27.     GetScreen( screen );
  28.     ExplodeBox( begx, begy, begx+1+longest, begy+1+numchoices );
  29.     for (i=0; i<numchoices; ++i)
  30.         AtSay( begx+1, begy+1+i, MP[i].Item );
  31.     for (;;) {
  32.         ChangeBlock( begx, begy, begx+1+longest, numchoices+begy+1, 0x07 );
  33.         ChangeBlock( begx+1, begy+1+ptr, begx+longest, begy+1+ptr, 0x70 );
  34.         AtSay( xx, yy, MP[ptr].Desc );
  35.         switch( ch = GComm() ) {
  36.             case CR:
  37.                 if ( -1 == MP[ptr].func() ) {
  38.                     PutScreen( screen );
  39.                     free( screen );
  40.                     return;
  41.                 }
  42.                 break;
  43.             case ESC:
  44.                 PutScreen( screen );
  45.                 free( screen );
  46.                 return;
  47.             case DOWN:
  48.                 if ( ++ptr >= numchoices )
  49.                     ptr = 0;
  50.                 break;
  51.             case UP:
  52.                 if ( --ptr < 0 )
  53.                     ptr = numchoices - 1;
  54.                 break;
  55.             default:
  56.                 i = ptr + 1;
  57.                 while ( i != ptr ) {
  58.                     if ( i >= numchoices ) i = 0;
  59.                     if ( toupper(MP[i].Item[0]) == toupper(ch) ||
  60.                          MP[i].FuncKey == ch ) {
  61.                         ptr = i;
  62.                         break;
  63.                     }
  64.                     i++;
  65.                 }
  66.                 break;
  67.         }
  68.     }
  69. }
  70.